from django.conf.urls.static import static
from django.urls import path, include, re_path
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from rest_framework import permissions

from application import settings

schema_view = get_schema_view(
    openapi.Info(
        title="Chat-message API",
        default_version="v1",
        description="Test description",
        terms_of_service="https://www.google.com/policies/terms/",
        contact=openapi.Contact(email="contact@snippets.local"),
        license=openapi.License(name="BSD License"),
    ),
    public=True,
    permission_classes=(permissions.AllowAny,),
)

urlpatterns = (
        [
            path(
                r'swagger/',
                schema_view.with_ui("swagger", cache_timeout=0),
                name="schema-swagger-ui",
            ),
            re_path(
                r"^swagger(?P<format>\.json|\.yaml)$",
                schema_view.without_ui(cache_timeout=0),
                name="schema-json",
            ),
            path(
                r"redoc/",
                schema_view.with_ui("redoc", cache_timeout=0),
                name="schema-redoc",
            ),
            re_path(
                r"^api-auth/", include("rest_framework.urls", namespace="rest_framework")
            ),
            path('api/chat/', include("apps.assistant.urls")),  # 会话模块
            path('api/users/', include("apps.UserManagement.urls")),  # 用户模块
            path('api/packages/', include("apps.PackageManagement.urls")),  # 套餐管理模块
            path('api/orders/', include("apps.OrderManagement.urls")),  # 订单模块
            path('api/payments/', include("apps.PaymentManagement.urls")),  # 支付模块
            path('api/templates/', include("apps.TemplateManagement.urls")),  # 模版管理模块
        ]
        + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
        + static(settings.STATIC_URL, document_root=settings.STATIC_URL)
        + [re_path(ele.get('re_path'), include(ele.get('include'))) for ele in settings.PLUGINS_URL_PATTERNS]
)
